// 基础类型定义
export interface ModelInfo {
  id: string;
  name: string;
  provider: string;
  description?: string;
  contextLength?: number;
  capabilities?: string[];
  pricing?: {
    input: number;
    output: number;
  };
}

export interface ModelCache {
  provider: string;
  models: ModelInfo[];
  lastUpdated: number;
  expiry: number;
}

export interface ValidationResult {
  isValid: boolean;
  error?: {
    code: string;
    message: string;
    suggestion?: string;
  };
  metadata?: {
    accountInfo?: any;
    availableModels?: string[];
    rateLimits?: any;
    model?: string;
    usage?: any;
    modelName?: string;
    warning?: string;
  };
}

export interface LLMConfig {
  llm: string;
  apiKey: string;
  modelName: string;
  options: {
    baseURL: string;
    timeout?: number;
    maxRetries?: number;
    [key: string]: any;
  };
}

export interface ExtendedLLMConfig extends LLMConfig {
  validation?: {
    lastChecked?: number;
    isValid?: boolean;
    error?: string;
  };
  models?: {
    cached?: ModelInfo[];
    lastUpdated?: number;
  };
}

export interface ExportedConfig {
  version: string;
  exportDate: string;
  config: LLMConfig;
  metadata?: {
    userAgent?: string;
    extensionVersion?: string;
    configHash?: string;
  };
}

export interface ImportResult {
  success: boolean;
  importedKeys: string[];
  skippedKeys: string[];
  errors?: string[];
}

export interface CacheEntry<T> {
  data: T;
  timestamp: number;
  expiry: number;
  version: string;
}

export interface ModelCacheData {
  [provider: string]: CacheEntry<ModelInfo[]>;
}

// 供应商类型
export type LLMProvider = 'openai' | 'anthropic' | 'openrouter' | 'openai-compatible';

// API适配器接口
export interface LLMAdapter {
  fetchModels(baseURL?: string, apiKey?: string): Promise<ModelInfo[]>;
  validateApiKey(apiKey: string, baseURL?: string): Promise<ValidationResult>;
}

// 错误类型
export enum ValidationErrorCode {
  INVALID_API_KEY = 'INVALID_API_KEY',
  INSUFFICIENT_PERMISSIONS = 'INSUFFICIENT_PERMISSIONS',
  RATE_LIMITED = 'RATE_LIMITED',
  SERVER_ERROR = 'SERVER_ERROR',
  NETWORK_ERROR = 'NETWORK_ERROR',
  TIMEOUT = 'TIMEOUT',
  UNKNOWN_ERROR = 'UNKNOWN_ERROR'
}